package com.example.demorabbitmqlisten.rabbitmq;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置消息转换器
 */
@Configuration
@ConditionalOnClass(RabbitTemplate.class) //有RabbitTemplate依赖才会生效，否则不生效
public class MqConfig {
    @Bean
    public MessageConverter messageConverter(){
        //使用json序列化发送消息
        return new Jackson2JsonMessageConverter();
    }
    //添加一个名为hello的队列
    @Bean
    public Queue helloQueue() {

        /**
         * name:队列名字
         * durable:是否支持持久化，默认true
         * exclusive:表示该消息队列是否只在当前connection中生效，默认是false
         * autoDelete:没有消息和连接时是否自动删除，默认时false
         */
        Queue hello = new Queue("hello",true,false,true);
        return hello;
    }

}
